<?php
/**
 * @Copyright   2008, XXXX-XXXX
 * All rights reserved. 
 * feature summary.
 * @filesource  SimpleFixCommand.php 
 * @author      lipeng <lipengage@gmain.com> 
 * @package     / 
 * @version     $Id: $ 
 */

class SimpleFixCommand extends DostuffCommand{
	public function excute() {

		if ($this->get_player()) {
			return true;
		}

		if ($this->is_slave() === true || $this->is_slave() === -1) {
			return true;
		}

		if ($this->check_cmd_catalog("messageId")) {
			return true;
		}

		if ($this->actor["cash"] < $this->catalog["cash"]) {
			$params["need"] = $this->catalog["cash"];
			$this->set_messageid(command::NOT_ENOUGH_MONEY);
			$this->set_params($params);
			return true;
		}

		$new_activity = $this->activitydb->activity_get_cmd_last_activity($this->actor["uid"], $this->target["uid"], $type);

		if ($new_activity["count"] == 1 && $new_activity["result"][0]["until"] > time()) {
			$params["activity"] = $new_activity["command"];
			$params["until"] = $new_activity["until"];
			$this->set_messageid(command::$SLAVE_AT_WORK);
			$this->set_params($params);
			return true;
		}

		$this->actor["cash"] -= $this->catalog["cash"];
		$this->userdb->user_update_byid($this->container, $this->actor["uid"], $this->actor);

		//save activity
		$new_activity = $this->new_activity(activity_dao::$FIX);
		$new_activity["until"] = time() + (3600 * $this->config['fix_interval'][0]);
		$this->activitydb->activity_insert($new_activity);

		$this->set_haserror(false);
		$this->set_messageid($this->catalog["messageId"]);
		$params["viewer"] = $this->actor;
		$params["target"] = $this->target;
		$this->set_params($params);
		return false;
	}
}
?>